package com.my.kq.dao;

import com.my.kq.entity.Position;
import com.my.kq.uitl.BaseDAO;

import java.util.List;

public class PositionDao extends BaseDAO {
    public Position posiselect(Integer number) throws Exception {
        String sql="select * from position where positionNumber=?";
        Object[]obj={number};
        Position one = getOne(sql, new Position(), obj);
        return one;
    }

    public void posixg(String educationc,Integer id) throws Exception {
        String sql="update position set name=? where id=?";
        Object[] obj={educationc,id};
        addOrupdOrdel(sql,obj);
    }

    //查询分页数据
    public List<Position> getPage(int pageNo)throws Exception{
        String sql="select * from position limit ?,?";
        //每页显示10条数据
        Object[]obj={(pageNo-1)*10,10};
        List<Position> list = getList(sql, new Position(), obj);
        return list;
    }

    //查询总数据条数
    public int getCount()throws Exception{
        String sql="select count(*) from position";
        Object[]obj={};
        int count = getCount(sql, obj);
        return count;
    }
    //通过id获取Position对象
    public Position getPosition(int id)throws Exception{
        String sql="select * from position where id=?";
        Object[]obj={id};
        Position one = getOne(sql, new Position(), obj);
        return one;
    }

    //修改position
    public void updatePosition(Position position)throws Exception{
        String sql="update position set name=? , level=? , notes=? where id=?";
        Object[]obj={position.getName(),position.getLevel(),position.getNotes(),position.getId()};
        addOrupdOrdel(sql,obj);
    }

    //通过id删除
    public void deletePosition(int id)throws Exception{
        String sql="delete from position where id=?";
        Object[]obj={id};
        addOrupdOrdel(sql,obj);
    }

    //通过position 新增
    public void addPosition(Position position)throws Exception{
        String sql="insert into position values(null,?,?,?,?)";
        Object[]obj={position.getPositionNumber(),position.getName(),position.getLevel(),position.getNotes()};
        addOrupdOrdel(sql,obj);
    }
    //获取最大positionNumber对象
    public List<Position> getAllPosition()throws Exception{
        String sql="select * from position";
        Object[]obj={};
        List<Position> list = getList(sql, new Position(), obj);
        return list;
    }
}
